from lovely.jsonrpc import proxy
from django.utils import simplejson

class TestJSONRPCTransport(object):
    """transport for testing"""

    def __init__(self, base, client=None):
        self.base = base
        self._client = client

    def request(self, requestBody):
        self._client.lastRequestBody = requestBody
        resp = self._client.post(self.base, requestBody,
                                content_type="application/json")
        return int(resp._status.split(' ')[0]), resp._body

def TestJSONRPCProxy(base, client):
    return proxy.ServerProxy(
        base,
        json_impl = simplejson,
        transport_impl=TestJSONRPCTransport, client=client)

